package findfirstword;
//找到第一个只出现一次的元素
public class Test {
    public static int solution(String s){
        int[] arr = new int[26];
        for (int i = 0; i < s.length() ; i++) {
            char ch = s.charAt(i);
            arr[ch-'a']++;
        }
        for (int i = 0; i < s.length(); i++) {
            if(arr[s.charAt(i)-'a'] == 1){
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        String s = "abad";
        System.out.println(solution(s));
    }
}
